package cn.jiyun.mailutils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailUtil {

    /**
     * 校验email格式
     *
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        boolean flag;
        try {
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    public static boolean sendEmail(String to, String subject, String content) {
        SenderMessage senderMessage = new SenderMessage();
        senderMessage.setContent(content);
        senderMessage.setFrom("1170596762@qq.com");
        senderMessage.setTo(to);
        senderMessage.setSubject(subject);
        senderMessage.setPersonal("积云教育");
        return SenderUtil.send(senderMessage);
    }

}
